<include file="../Public/_top" />
<div class="content">
  <div class="wrap">
  <include file="./_left" />
    <div class="con_main">
      <div class="con_tit">
        <ul class="con_link">
          <li class="on"><a href="javascript:;">已测试</a></li>
          <li><a href="{:U('public/TestData/addPeportTest')}">新建测试</a></li>
        </ul>
      <div class="search_wrap">
        <input class="search_inp" type="text" id="name" placeholder="按姓名搜索">
        <input class="search_btn" type="submit" value="" onclick="select_filter();">
      </div>
      </div>
      <div style="width:100%;height:140px;padding:15px;">
        <div class="sel_box">
          选择时间：
          <select id="year" class="sel">
            <option value="">--------请选择--------</option>
            <volist name="year" id="year">
              <option value="{$year}">{$year}</option>
            </volist>
          </select>
        </div>
        <div class="sel_box">
          测试季度：
          <select id="test_number" class="sel">
            <option value="">--------请选择--------</option>
            <option value="1">春季</option>
            <option value="2">秋季</option>
          </select>
        </div>
        <div class="sel_box">
          选择年级：
          <select id="grade" class="sel" onchange="selectGrade();">
              <option value="">--------请选择--------</option>
              <option value="1">大班</option>
              <option value="2">中班</option>
              <option value="3">小班</option>
              <option value="4">混龄班</option>
          </select>
        </div>
        <div class="sel_box">
          选择班级：
            <select id="Class" class="sel">
              <option value="">--------请选择--------</option>
            </select>
        </div>
        <div class="action_link tc" style="margin-top:90px;">
          <a class="dowm" href="javascript:select_filter();">确定</a>
        </div>
      </div>
      <div class="con_tit">
        <table class="table table_title t7_2">
          <tr>
            <td>姓名</td>
            <td>年级</td>
            <td>班级</td>
            <td>测试季度</td>
            <td>测试年份</td>
            <td>完成度</td>
            <td>操作</td>
          </tr>
        </table>
      </div>
      <div class="con_box" id="test_list"></div>
      <div class="action_link tc" id="allreport" style="margin-left: -200px;"></div>
    </div>
  </div>
</div>
<script>
var userGroup="<?php echo $userGroup; ?>";
var classId="<?php echo $classId; ?>";
if(userGroup==5){
  $("#grade").attr("disabled","disabled");  
  $("#Class").attr("disabled","disabled"); 
    $.ajax({
    type: "GET",
    url:"{:U('public/TestData/getList')}",
    data:"is_report=1&p=1&Class="+classId,
    dataType:"json",
    success:function(data){
        appendHtml(data);
    }
  });
}
 //追加html
function appendHtml(data){
  $("#test_list").html("");
  $("#test_list").append(data.data);
  var html="<div class='pagebox'>";
  if(data.nowPage>1 ){
    page=data.nowPage-1;
    html+="<a href=\"javascript:getList("+page+")\">上一页</a>";
  }
  for (var i = 1; i <=data.totalPages; i++) {
    if(i==data.nowPage){
        html+="<a href=\"javascript:getList("+i+")\" class='on'>"+i+"</a>";
    }else{
        html+="<a href=\"javascript:getList("+i+")\" >"+i+"</a>";  
    }
  };
  if(data.totalPages>1 && data.nowPage<data.totalPages){
      page=data.nowPage+1;
      html+="<a href=\"javascript:getList("+page+")\" id=\"getList\">下一页</a>";
  }
  html+="</div>";
  $("#test_list").append(html);
  if(data.data){
    $("#allreport").html("<a class='dowm' href='javascript:allreport();' style='margin-left:-700px;'>批量导出</a>"); 
  }
}

//查看更多
function getList(page){
  p=page;
  ajaxBang();
}
function allreport(){
  var test_number=$("#test_number").val();
  var Class=$("#Class").val();
  var year=$("#year").val();
  if(Class==0){
    var Class=classId;
  }
  window.location.href="{:U('public/TestData/doexport')}"+"&test_number="+test_number+"&Class="+Class+"&year="+year+"&type=1";
}
//筛选条件
function select_filter(){
  var name=$("#name").val();
  var year=$("#year").val();
  var test_number=$("#test_number").val();
  var Class=$("#Class").val();
  var class_type=$("#grade").val();
  if(userGroup==5){
    Class=classId;
  }
  if(name==""){
    if(year==0){
      alert("请选择时间");
      return ;
    }
    if(test_number==0){
      alert("请选择季度");
      return ;
    } 
    if(Class==0){
      alert("请选择班级");
      return ;
    }
  }
  p=1;
  $.ajax({
    type: "GET",
    url:"{:U('public/TestData/getList')}",
    data:"is_report=1&p="+p+"&name="+name+"&year="+year+"&test_number="+test_number+"&Class="+Class+"&class_type="+class_type,
    dataType:"json",
    success:function(data){
      appendHtml(data);
    }
  });
}
//请求事件
function ajaxBang(){
  var class_type=$("#grade").val();
  $.ajax({
    type: "GET",
    url:"{:U('public/TestData/getList')}",
     data:"is_report=1&p="+p+"&name="+name+"&year="+year+"&test_number="+test_number+"&Class="+Class+"&class_type="+class_type,
    dataType:"json",
    success:function(data){
        appendHtml(data);
    }
  });
}
function selectGrade(){
  var grade       = $("#grade").val();
  var test_number = $("#test_number").val();
  var year        = $("#year").val();
  if(grade!=""){
    $.ajax({
      type: "GET",
      url:"{:U('public/TestData/getClass')}",
      data:"is_report=1&class_type="+grade+"&test_number="+test_number+'&year='+year,
      dataType:"json",
      success:function(data){
        $("#Class").html("");
        $("#Class").append("<option value=''>--------请选择--------</option>");
        $.each(data,function(i,item){
          $("#Class").append("<option value='"+item.class_id+"'>"+item.class_name+"</option>");
        }); 
      }
    });
  }
}
</script>
<include file="../Public/_foot" />